<?php
/**
 * Created by JetBrains PhpStorm.
 * User: T420
 * Date: 11/29/12
 * Time: 8:48 AM
 * To change this template use File | Settings | File Templates.
 */
class Models_Product extends Libs_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    public function getcatelogy()
    {
        $this->db->connect();
        $list=$this->db->executeQuery("select * from lb_menuproduct where status=1");
        $this->db->disconnect();
        return $list;
    }
    public function getproduct($pfid)
    {
        if($pfid!='')
        {
            $sql="select * from lb_product a where pfid='$pfid'";
        }
        else
            $sql="select * from lb_product a";
        $this->db->connect();
        $list=$this->db->executeQuery($sql);
        $this->db->disconnect();
        return $list;

    }
    public function prodetail($id)
    {
        $this->db->connect();
        $list=$this->db->executeQuery("select * from lb_product where pid='$id'");
        $this->db->disconnect();
        return $list;
    }
    public function updatepro($masp,$mahang,$maloai,$nhacungcap,$tensp,$mota,$soluong,$gia,$anh,$baohanh,$trangthaisp)
    {
        $sql="update lb_product set mfid='$mahang',pfid='$maloai',distributor='$nhacungcap',pname='$tensp',detail='$mota',quantity='$soluong',price='$gia',picture='$anh',warranty='$baohanh',status='$trangthaisp' where pid='$masp'";
        $this->db->connect();
        $list=$this->db->query($sql);
        $this->db->disconnect();
    }
    public function getmenupro()
    {
        $this->db->connect();
        $list=$this->db->executeQuery("select * from lb_menuproduct where status=1");
        $this->db->disconnect();
        return $list;
    }
    public function getmanufactures()
    {
        $this->db->connect();
        $list=$this->db->executeQuery("select * from lb_manufactures where status=1");
        $this->db->disconnect();
        return $list;
    }
    public function checkproduct($pname,$pid)
    {
        $this->db->connect();
        if($pid!=0)
            $sql="select * from lb_product where pname='$pname' and pid!='$pid'";
        else
            $sql="select * from lb_product where pname='$pname'";
        $list=$this->db->executeQuery($sql);
        $this->db->disconnect();
        return $list;
    }
    public function delpro($id)// xoa san pham
    {
        $this->db->connect();
        $list=$this->db->query("delete from lb_product where pid in ('$id')");
        $this->db->disconnect();
    }
    public function insertpro($mahang,$maloai,$nhacungcap,$ngaynhap,$tensp,$mota,$soluong,$gia,$anh,$baohanh,$trangthaisp)//them san pham
    {
        $this->db->connect();
        $list=$this->db->query("insert lb_product(mfid,pfid,distributor,postdate,pname,detail,quantity,price,picture,warranty,status) value ('$mahang','$maloai','$nhacungcap','$ngaynhap','$tensp','$mota','$soluong','$gia','$anh','$baohanh','$trangthaisp')");
        $this->db->disconnect();
    }
    public function seachpro($pname)//tim kiem san pham theo ten
    {
        $this->db->connect();
        $list=$this->db->executeQuery("select * from lb_product where pname like '%$pname%'");
        $this->db->disconnect();
        return $list;
    }
}
